home *** CD-ROM | disk | FTP | other *** search
/ L' Effet Pommier 3 / L'Effet Pommier - Volume 03.iso / Graphismes / Bitmap / NIH Image 1.59 / Macros / Serial I⁄O < prev    next >
Text File  |  1993-11-24  |  4KB  |  157 lines

  1. macro 'Open Serial Port [O]';
  2. begin
  3.   RequiresVersion(1.48);
  4.   OpenSerial('9600 baud,no parity,eight data,one stop');
  5. end;
  6.  
  7.  
  8. macro 'Put Serial [P]';
  9. begin
  10.    PutSerial(GetString('Enter a string:'));
  11. end;
  12.  
  13.  
  14. macro 'Serial Output Test [T]';
  15. var
  16.   i:integer;
  17. begin
  18.   SetCursor('Watch');
  19.   for i:=1 to 10 do
  20.     PutSerial('The is line ',i:3,chr(13),chr(10));
  21.   end;
  22. end;
  23.  
  24.  
  25. macro 'Get Serial and Echo [G]';
  26. var
  27.   i:integer;
  28.   ch:string; {actually one char}
  29. begin
  30.   ShowMessage('Press mouse button to abort.');
  31.   SetCursor('Watch');
  32.   repeat until GetSerial=''; {Flush input buffer}
  33.   repeat
  34.     ch:=GetSerial; {returns null string if input buffer empty}
  35.     if ch<>'' then ShowMessage('char="',ch,'" (',ord(ch):1,')');
  36.     PutSerial(ch);
  37.     if ch=chr(13) then PutSerial(chr(10)); {if return send line feed}
  38.   until button;
  39. end;
  40.  
  41. macro 'Capture Serial Input [C]';
  42. {Captures serial input to a text window.}
  43. var
  44.   x,y,width,height,cc,tc:integer;
  45.   ch:string; {actually one char}
  46. begin
  47.   RequiresVersion(1.52);
  48.   OpenSerial('9600');
  49.   NewTextWindow('Serial Input');
  50.   cc:=0; tc:=0;
  51.   ShowMessage('Use command-period to abort');
  52.   SetCursor('Watch');
  53.   repeat
  54.      repeat tc:=tc+1; ch:=GetSerial until (ch<>'') or button;
  55.      write(ch);
  56.      cc:=cc+1;
  57.   until button;
  58.  end;
  59.  
  60. macro 'Display Serial Input╔';
  61. {Displays serial input in a window.}
  62. var
  63.   x,y,width,height,count,line:integer;
  64.   ch:string; {actually one char}
  65.   BaudRate:string;
  66. begin
  67.   RequiresVersion(1.48);
  68.   repeat
  69.     BaudRate:=Getstring('Baud Rate(1200, 2400, 9600 or 19200)','9600');
  70.   until (BaudRate='1200') or (BaudRate='2400') or(BaudRate='9600') or (BaudRate='19200');
  71.   OpenSerial(BaudRate);
  72.   width:=500;
  73.   height:=500;
  74.   SetNewSize(width,height);
  75.   SetForeground(255);
  76.   SetBackground(0);
  77.   MakeNewWindow('Serial Input');
  78.   SetCursor('Watch');
  79.   SetFont('Monaco');
  80.   SetText('With background; Left Justified');
  81.   SetFontSize(9);
  82.   MoveTo(8,8);
  83.   count:=0;
  84.   line:=0;
  85.   ShowMessage('Press mouse button to abort');
  86.   repeat
  87.      ch:=GetSerial;
  88.      if ch<>'' then begin
  89.        count:=count+1;
  90.        if (ord(ch)=13) or (count=80) then begin {13=Carriage Return}
  91.          writeln(ch);
  92.          count:=0
  93.          line:=line+1;
  94.          if line=54 then begin
  95.            Clear;
  96.            moveto(8,8);
  97.            line:=0;
  98.          end;
  99.        end else
  100.          write(ch);
  101.      end;
  102.    until button;
  103. end;
  104.  
  105.  
  106. procedure GetResponse;
  107. {Gets responses to commands sent to the Newport 2-axis controller}
  108. var
  109.   ch:string;
  110.   TimeOutTicks:integer;
  111.   TimeOUt:boolean;
  112. begin
  113.   response:='';
  114.   TimeOutTicks:=TickCount+60; {1 sec.}
  115.   repeat
  116.     ch:=GetSerial;
  117.     if ord(ch)>=32 {ignore control characters}
  118.       then response:=concat(response,ch);
  119.     timeout:=TickCount>TimeOutTicks;
  120.   until (ch=return) or TimeOut;
  121.   if TimeOut then response:=concat(response,'[1 second time out]');
  122. end;
  123.  
  124.  
  125. macro 'Test Newport Motion Controller╔[N]';
  126. {
  127. Simple macro to test the Newport PMC200-P programmable 2-axis
  128. motion controller. Before starting, connect the PMC200-P to 
  129. the Mac's modem port. This can be done using a modem cable
  130. and a 9-pin to 25-pin adapter consisting of a female 25-pin
  131. connector wired back-to-back with a female 9-pin connector
  132. acording to the table below.
  133.  
  134.    9-pin      25-pin
  135.      2 <------> 3  (receive data)
  136.      3 <------> 2  (transmit data)
  137.      5 <------> 7  (signal ground)
  138.  
  139. Note: RS-232 INPUT ECHO MODE must be disabled. The phone
  140. number for Newport is 714-253-1665.
  141. }
  142. var
  143.   cmd,response,linefeed,return:string;
  144. begin
  145.   RequiresVersion(1.48);
  146.   linefeed:=chr(10);
  147.   return:=chr(13);
  148.   OpenSerial('9600 baud,no parity,eight data,one stop');
  149.   repeat
  150.     cmd:=GetString('Enter PMC200-P Command:','*IDN?');
  151.     repeat until GetSerial=''; {flush input buffer}
  152.     PutSerial(cmd,return,linefeed);
  153.     GetResponse;
  154.     PutMessage(response)
  155.   until button;
  156. end;
  157.